1 using UnityEngine;
2 using
System.Collections;
3
4 namespace
Dialog
5 {
6     
public class DialogUnity : MonoBehaviour
7     {
8         
public Buttons buttons;
9         
private BitmapFont bitmapFont;
10         
public GameObject label1;
11         
public GameObject label2;
12
13         
public void setDialogOne(DialogButton dialogOK)
14         {
15             buttons.setButtonNumber(
1);
16             buttons.buttonX.GetComponent<Button>().addClickListener(dialogOK);
17         }
18
19         
public void setDialogTwo(DialogButton dialogOK, DialogButton dialogClose)
20         {
21             buttons.setButtonNumber(
2);
22             buttons.buttonOk.GetComponent<Button>().addClickListener(dialogOK);
23             buttons.buttonClose.GetComponent<Button>().addClickListener(dialogClose);
24         }
25
26         
public void setText(string oneline)
27         {
28             bitmapFont =
new BitmapFont("Fonts/shop_font", "Fonts/shop_font_xml", label1);
29             bitmapFont.setText(oneline,
0, 15);
30             Transform[] fontTransforms = label1.GetComponentsInChildren<Transform>(
true);
31             
for (int i = 0; i < fontTransforms.Length; i++)
32             {
33                 
if (fontTransforms[i].gameObject.GetComponent<SpriteRenderer>() != null)
34                 {
35                     fontTransforms[i].gameObject.layer = LayerMask.NameToLayer(
"GUI");
36                     fontTransforms[i].gameObject.GetComponent<SpriteRenderer>().sortingLayerName =
"GUI";
37                 }
38             }
39         }
40
41         
public void setText(string line1, string line2)
42         {
43             bitmapFont =
new BitmapFont("Fonts/shop_font", "Fonts/shop_font_xml", label1);
44             bitmapFont.setText(line1,
0, 15);
45             Transform[] fontTransforms = label1.GetComponentsInChildren<Transform>(
true);
46             
for (int i = 0; i < fontTransforms.Length; i++)
47             {
48
49                 
if (fontTransforms[i].gameObject.GetComponent<SpriteRenderer>() != null)
50                 {
51                     fontTransforms[i].gameObject.layer = LayerMask.NameToLayer(
"GUI");
52                     fontTransforms[i].gameObject.GetComponent<SpriteRenderer>().sortingLayerName =
"GUI";
53                 }
54             }
55
56             BitmapFont bitmapFont2 =
new BitmapFont(bitmapFont, label2);
57             bitmapFont2.setText(line2,
0, 15);
58             Transform[] fontTransforms2 = label2.GetComponentsInChildren<Transform>(
true);
59             
for (int i = 0; i < fontTransforms2.Length; i++)
60             {
61                 
if (fontTransforms2[i].gameObject.GetComponent<SpriteRenderer>() != null)
62                 {
63                     fontTransforms2[i].gameObject.layer = LayerMask.NameToLayer(
"GUI");
64                     fontTransforms2[i].gameObject.GetComponent<SpriteRenderer>().sortingLayerName =
"GUI";
65                 }
66             }
67         }
68
69         
public void Start()
70         {
71             gameObject.SetActive(
false);
72         }
73
74         
public void showDialog()
75         {
76             gameObject.SetActive(
true);
77             gameObject.transform.localPosition =
new Vector3(0, 4.8f, gameObject.transform.localPosition.z);
78             
if (gameObject.GetComponent<Actor>() != null)
79                 Destroy(gameObject.GetComponent<Actor>());
80             gameObject.AddComponent<Actor>().addAction(
new ActionMoveTo(0, 0, 0.5f, Interpolation.swingOut));
81         }
82
83         
public void hideDialog()
84         {
85             gameObject.SetActive(
false);
86             gameObject.transform.localPosition =
new Vector3(0, 4.8f, gameObject.transform.localPosition.z);
87         }
88     }
89
90     
public delegate void DialogButton();
91 }



Trò chơi đua xe động vật trong UNITY Engine 114.723 lượt xem

Gõ tìm kiếm nhanh...